<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="generator" content="VuePress 2.0.0-beta.63">
    <style>
      :root {
        --c-bg: #fff;
      }
      html.dark {
        --c-bg: #22272e;
      }
      html, body {
        background-color: var(--c-bg);
      }
    </style>
    <script>
      const userMode = localStorage.getItem('vuepress-color-scheme');
			const systemDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
			if (userMode === 'dark' || (userMode !== 'light' && systemDarkMode)) {
				document.documentElement.classList.toggle('dark', true);
			}
    </script>
    <link rel="apple-touch-icon" href="/preview/dev-edge/static/images/icons/apple-touch-icon.png"><link rel="icon" type="image/png" sizes="32x32" href="/preview/dev-edge/static/images/icons/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/preview/dev-edge/static/images/icons/favicon-32x32.png"><link rel="mask-icon" color="#5bbad5" href="/preview/dev-edge/static/images/icons/safari-pinned-tab.svg"><link rel="manifest" href="/preview/dev-edge/manifest.webmanifest"><meta name="theme-color" content="#3eaf7c"><title>CSS知识点 | 编程宝典</title><meta name="description" content="技术文档系列">
    <link rel="preload" href="/preview/dev-edge/assets/style-f70c0240.css" as="style"><link rel="stylesheet" href="/preview/dev-edge/assets/style-f70c0240.css">
    <link rel="modulepreload" href="/preview/dev-edge/assets/app-5517e208.js"><link rel="modulepreload" href="/preview/dev-edge/assets/index.html-6ead1acd.js"><link rel="modulepreload" href="/preview/dev-edge/assets/index.html-5dc09f61.js"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-b0802b3f.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-91808b4b.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/companyWebSite.html-9e7a30c8.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-4262c6b6.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-6497e968.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-2b3ce734.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-c1d52a82.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-193e0fce.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-8ef690da.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-e16c539b.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-2612aedd.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/element.html-433d6fa7.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/others.html-0fd00d80.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-d5a68135.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-f9d64ee4.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/note.html-c888e7ae.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/standard.html-a01ab960.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/chapter01.html-9437ac94.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/3Dweb.html-a089b8c2.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/efficientOffice.html-738b652c.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/jsBase.html-57994080.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/shareDays.html-3bf22bb6.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-f50cfc3a.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-d5c469ee.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/404.html-1f2dab39.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-5eb236d0.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-1a6bf188.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/companyWebSite.html-cf3c257a.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-0825c4b1.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-60fc4bf3.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-ade72257.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-6916a41b.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-7604bfc1.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-b898dcab.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-27bb8266.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-d7c5567b.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/element.html-67b8ba8a.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/others.html-243c60b2.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-38035162.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-301c45fe.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/note.html-a409283d.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/standard.html-1078c00a.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/chapter01.html-a87c4022.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/3Dweb.html-ce93ff55.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/efficientOffice.html-eb2a5cdf.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/jsBase.html-598d0a7a.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/shareDays.html-44350d8b.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-58ddc7ce.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index.html-a8b21767.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/404.html-2796e91e.js" as="script"><link rel="prefetch" href="/preview/dev-edge/assets/index-e32a7948.js" as="script">
  </head>
  <body>
    <div id="app"><!--[--><div class="theme-container"><!--[--><header class="navbar"><div class="toggle-sidebar-button" title="toggle sidebar" aria-expanded="false" role="button" tabindex="0"><div class="icon" aria-hidden="true"><span></span><span></span><span></span></div></div><span><a href="/preview/dev-edge/" class=""><img class="logo" src="/preview/dev-edge/static/images/icons/android-chrome-192x192.png" alt="编程宝典"><span class="site-name can-hide">编程宝典</span></a></span><div class="navbar-items-wrapper" style=""><!--[--><!--]--><nav class="navbar-items can-hide"><!--[--><div class="navbar-item"><div class="navbar-dropdown-wrapper"><button class="navbar-dropdown-title" type="button" aria-label="前端"><span class="title">前端</span><span class="arrow down"></span></button><button class="navbar-dropdown-title-mobile" type="button" aria-label="前端"><span class="title">前端</span><span class="right arrow"></span></button><ul style="display:none;" class="navbar-dropdown"><!--[--><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>基础知识</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/preview/dev-edge/frontend/html/" class="" aria-label="html"><!--[--><!--]--> html <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a aria-current="page" href="/preview/dev-edge/frontend/css/" class="router-link-active router-link-exact-active router-link-active" aria-label="css"><!--[--><!--]--> css <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/preview/dev-edge/frontend/javascript/" class="" aria-label="Javascript"><!--[--><!--]--> Javascript <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>高级进阶</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/preview/dev-edge/frontend/vue/" class="" aria-label="Vue"><!--[--><!--]--> Vue <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>插件及组件库</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/preview/dev-edge/frontend/libs/" class="" aria-label="导航"><!--[--><!--]--> 导航 <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>综合</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/preview/dev-edge/frontend/others/standard" class="" aria-label="前端开发规范"><!--[--><!--]--> 前端开发规范 <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/preview/dev-edge/frontend/others/note" class="" aria-label="前端知识点"><!--[--><!--]--> 前端知识点 <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><!--]--></ul></div></div><div class="navbar-item"><div class="navbar-dropdown-wrapper"><button class="navbar-dropdown-title" type="button" aria-label="后端"><span class="title">后端</span><span class="arrow down"></span></button><button class="navbar-dropdown-title-mobile" type="button" aria-label="后端"><span class="title">后端</span><span class="right arrow"></span></button><ul style="display:none;" class="navbar-dropdown"><!--[--><li class="navbar-dropdown-item"><a href="/preview/dev-edge/backend/java/" class="" aria-label="java"><!--[--><!--]--> java <!--[--><!--]--></a></li><li class="navbar-dropdown-item"><a href="/preview/dev-edge/backend/python/" class="" aria-label="python"><!--[--><!--]--> python <!--[--><!--]--></a></li><!--]--></ul></div></div><div class="navbar-item"><a href="/preview/dev-edge/storage/" class="" aria-label="版本库"><!--[--><!--]--> 版本库 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/preview/dev-edge/manage/" class="" aria-label="管理"><!--[--><!--]--> 管理 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/preview/dev-edge/project/" class="" aria-label="项目"><!--[--><!--]--> 项目 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/preview/dev-edge/system/" class="" aria-label="系统"><!--[--><!--]--> 系统 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/preview/dev-edge/share/" class="" aria-label="分享"><!--[--><!--]--> 分享 <!--[--><!--]--></a></div><div class="navbar-item"><a class="external-link" href="https://gitee.com/chengmaofeng/dev-edge" rel="noopener noreferrer" target="_blank" aria-label="Gitee"><!--[--><!--]--> Gitee <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><!--]--></nav><!--[--><!--]--><button class="toggle-color-mode-button" title="toggle color mode"><svg style="" class="icon" focusable="false" viewBox="0 0 32 32"><path d="M16 12.005a4 4 0 1 1-4 4a4.005 4.005 0 0 1 4-4m0-2a6 6 0 1 0 6 6a6 6 0 0 0-6-6z" fill="currentColor"></path><path d="M5.394 6.813l1.414-1.415l3.506 3.506L8.9 10.318z" fill="currentColor"></path><path d="M2 15.005h5v2H2z" fill="currentColor"></path><path d="M5.394 25.197L8.9 21.691l1.414 1.415l-3.506 3.505z" fill="currentColor"></path><path d="M15 25.005h2v5h-2z" fill="currentColor"></path><path d="M21.687 23.106l1.414-1.415l3.506 3.506l-1.414 1.414z" fill="currentColor"></path><path d="M25 15.005h5v2h-5z" fill="currentColor"></path><path d="M21.687 8.904l3.506-3.506l1.414 1.415l-3.506 3.505z" fill="currentColor"></path><path d="M15 2.005h2v5h-2z" fill="currentColor"></path></svg><svg style="display:none;" class="icon" focusable="false" viewBox="0 0 32 32"><path d="M13.502 5.414a15.075 15.075 0 0 0 11.594 18.194a11.113 11.113 0 0 1-7.975 3.39c-.138 0-.278.005-.418 0a11.094 11.094 0 0 1-3.2-21.584M14.98 3a1.002 1.002 0 0 0-.175.016a13.096 13.096 0 0 0 1.825 25.981c.164.006.328 0 .49 0a13.072 13.072 0 0 0 10.703-5.555a1.01 1.01 0 0 0-.783-1.565A13.08 13.08 0 0 1 15.89 4.38A1.015 1.015 0 0 0 14.98 3z" fill="currentColor"></path></svg></button><form class="search-box" role="search"><input type="search" autocomplete="off" spellcheck="false" value><!----></form></div></header><!--]--><div class="sidebar-mask"></div><!--[--><aside class="sidebar"><nav class="navbar-items"><!--[--><div class="navbar-item"><div class="navbar-dropdown-wrapper"><button class="navbar-dropdown-title" type="button" aria-label="前端"><span class="title">前端</span><span class="arrow down"></span></button><button class="navbar-dropdown-title-mobile" type="button" aria-label="前端"><span class="title">前端</span><span class="right arrow"></span></button><ul style="display:none;" class="navbar-dropdown"><!--[--><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>基础知识</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/preview/dev-edge/frontend/html/" class="" aria-label="html"><!--[--><!--]--> html <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a aria-current="page" href="/preview/dev-edge/frontend/css/" class="router-link-active router-link-exact-active router-link-active" aria-label="css"><!--[--><!--]--> css <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/preview/dev-edge/frontend/javascript/" class="" aria-label="Javascript"><!--[--><!--]--> Javascript <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>高级进阶</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/preview/dev-edge/frontend/vue/" class="" aria-label="Vue"><!--[--><!--]--> Vue <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>插件及组件库</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/preview/dev-edge/frontend/libs/" class="" aria-label="导航"><!--[--><!--]--> 导航 <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><li class="navbar-dropdown-item"><!--[--><h4 class="navbar-dropdown-subtitle"><span>综合</span></h4><ul class="navbar-dropdown-subitem-wrapper"><!--[--><li class="navbar-dropdown-subitem"><a href="/preview/dev-edge/frontend/others/standard" class="" aria-label="前端开发规范"><!--[--><!--]--> 前端开发规范 <!--[--><!--]--></a></li><li class="navbar-dropdown-subitem"><a href="/preview/dev-edge/frontend/others/note" class="" aria-label="前端知识点"><!--[--><!--]--> 前端知识点 <!--[--><!--]--></a></li><!--]--></ul><!--]--></li><!--]--></ul></div></div><div class="navbar-item"><div class="navbar-dropdown-wrapper"><button class="navbar-dropdown-title" type="button" aria-label="后端"><span class="title">后端</span><span class="arrow down"></span></button><button class="navbar-dropdown-title-mobile" type="button" aria-label="后端"><span class="title">后端</span><span class="right arrow"></span></button><ul style="display:none;" class="navbar-dropdown"><!--[--><li class="navbar-dropdown-item"><a href="/preview/dev-edge/backend/java/" class="" aria-label="java"><!--[--><!--]--> java <!--[--><!--]--></a></li><li class="navbar-dropdown-item"><a href="/preview/dev-edge/backend/python/" class="" aria-label="python"><!--[--><!--]--> python <!--[--><!--]--></a></li><!--]--></ul></div></div><div class="navbar-item"><a href="/preview/dev-edge/storage/" class="" aria-label="版本库"><!--[--><!--]--> 版本库 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/preview/dev-edge/manage/" class="" aria-label="管理"><!--[--><!--]--> 管理 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/preview/dev-edge/project/" class="" aria-label="项目"><!--[--><!--]--> 项目 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/preview/dev-edge/system/" class="" aria-label="系统"><!--[--><!--]--> 系统 <!--[--><!--]--></a></div><div class="navbar-item"><a href="/preview/dev-edge/share/" class="" aria-label="分享"><!--[--><!--]--> 分享 <!--[--><!--]--></a></div><div class="navbar-item"><a class="external-link" href="https://gitee.com/chengmaofeng/dev-edge" rel="noopener noreferrer" target="_blank" aria-label="Gitee"><!--[--><!--]--> Gitee <span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!--[--><!--]--></a></div><!--]--></nav><!--[--><!--]--><ul class="sidebar-items"><!--[--><li><p tabindex="0" class="sidebar-item sidebar-heading active collapsible">基础知识 <span class="down arrow"></span></p><ul style="" class="sidebar-item-children"><!--[--><li><a href="/preview/dev-edge/frontend/html/" class="sidebar-item" aria-label="HTML基础知识"><!--[--><!--]--> HTML基础知识 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/" class="router-link-active router-link-exact-active router-link-active sidebar-item active" aria-label="CSS知识点"><!--[--><!--]--> CSS知识点 <!--[--><!--]--></a><ul style="" class="sidebar-item-children"><!--[--><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#基础知识" class="router-link-active router-link-exact-active sidebar-item" aria-label="基础知识"><!--[--><!--]--> 基础知识 <!--[--><!--]--></a><ul style="" class="sidebar-item-children"><!--[--><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#什么是css" class="router-link-active router-link-exact-active sidebar-item" aria-label="什么是css？"><!--[--><!--]--> 什么是css？ <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#css的历史和版本" class="router-link-active router-link-exact-active sidebar-item" aria-label="css的历史和版本"><!--[--><!--]--> css的历史和版本 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#css语法的结构" class="router-link-active router-link-exact-active sidebar-item" aria-label="css语法的结构"><!--[--><!--]--> css语法的结构 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#css选择器-如何选择元素" class="router-link-active router-link-exact-active sidebar-item" aria-label="css选择器，如何选择元素"><!--[--><!--]--> css选择器，如何选择元素 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#css属性和值的基础知识" class="router-link-active router-link-exact-active sidebar-item" aria-label="css属性和值的基础知识"><!--[--><!--]--> css属性和值的基础知识 <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#排版和布局" class="router-link-active router-link-exact-active sidebar-item" aria-label="排版和布局"><!--[--><!--]--> 排版和布局 <!--[--><!--]--></a><ul style="" class="sidebar-item-children"><!--[--><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#盒子模型的概念" class="router-link-active router-link-exact-active sidebar-item" aria-label="盒子模型的概念"><!--[--><!--]--> 盒子模型的概念 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#块级元素和行内元素的区别" class="router-link-active router-link-exact-active sidebar-item" aria-label="块级元素和行内元素的区别"><!--[--><!--]--> 块级元素和行内元素的区别 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#浮动和清除浮动" class="router-link-active router-link-exact-active sidebar-item" aria-label="浮动和清除浮动"><!--[--><!--]--> 浮动和清除浮动 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#定位-绝对定位和相对定位" class="router-link-active router-link-exact-active sidebar-item" aria-label="定位，绝对定位和相对定位"><!--[--><!--]--> 定位，绝对定位和相对定位 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#弹性盒子模型-flexbox-的概念" class="router-link-active router-link-exact-active sidebar-item" aria-label="弹性盒子模型（flexbox）的概念"><!--[--><!--]--> 弹性盒子模型（flexbox）的概念 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#网格布局-grid-的概念" class="router-link-active router-link-exact-active sidebar-item" aria-label="网格布局（grid）的概念"><!--[--><!--]--> 网格布局（grid）的概念 <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#样式化文本" class="router-link-active router-link-exact-active sidebar-item" aria-label="样式化文本"><!--[--><!--]--> 样式化文本 <!--[--><!--]--></a><ul style="" class="sidebar-item-children"><!--[--><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#字体样式和字体大小" class="router-link-active router-link-exact-active sidebar-item" aria-label="字体样式和字体大小"><!--[--><!--]--> 字体样式和字体大小 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#文本颜色和背景颜色" class="router-link-active router-link-exact-active sidebar-item" aria-label="文本颜色和背景颜色"><!--[--><!--]--> 文本颜色和背景颜色 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#文本对齐方式和行高" class="router-link-active router-link-exact-active sidebar-item" aria-label="文本对齐方式和行高"><!--[--><!--]--> 文本对齐方式和行高 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#文本装饰-如下划线、删除线和强调" class="router-link-active router-link-exact-active sidebar-item" aria-label="文本装饰，如下划线、删除线和强调"><!--[--><!--]--> 文本装饰，如下划线、删除线和强调 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#阴影和轮廓效果" class="router-link-active router-link-exact-active sidebar-item" aria-label="阴影和轮廓效果"><!--[--><!--]--> 阴影和轮廓效果 <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#图像和背景" class="router-link-active router-link-exact-active sidebar-item" aria-label="图像和背景"><!--[--><!--]--> 图像和背景 <!--[--><!--]--></a><ul style="" class="sidebar-item-children"><!--[--><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#背景颜色和背景图像" class="router-link-active router-link-exact-active sidebar-item" aria-label="背景颜色和背景图像"><!--[--><!--]--> 背景颜色和背景图像 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#背景尺寸和背景重复" class="router-link-active router-link-exact-active sidebar-item" aria-label="背景尺寸和背景重复"><!--[--><!--]--> 背景尺寸和背景重复 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#边框和圆角" class="router-link-active router-link-exact-active sidebar-item" aria-label="边框和圆角"><!--[--><!--]--> 边框和圆角 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#图像透明度和过渡效果" class="router-link-active router-link-exact-active sidebar-item" aria-label="图像透明度和过渡效果"><!--[--><!--]--> 图像透明度和过渡效果 <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#动画和交互" class="router-link-active router-link-exact-active sidebar-item" aria-label="动画和交互"><!--[--><!--]--> 动画和交互 <!--[--><!--]--></a><ul style="" class="sidebar-item-children"><!--[--><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#css动画和关键帧" class="router-link-active router-link-exact-active sidebar-item" aria-label="css动画和关键帧"><!--[--><!--]--> css动画和关键帧 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#css过渡效果" class="router-link-active router-link-exact-active sidebar-item" aria-label="css过渡效果"><!--[--><!--]--> css过渡效果 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#悬停效果和活动状态效果" class="router-link-active router-link-exact-active sidebar-item" aria-label="悬停效果和活动状态效果"><!--[--><!--]--> 悬停效果和活动状态效果 <!--[--><!--]--></a><!----></li><li><a aria-current="page" href="/preview/dev-edge/frontend/css/#响应式设计和媒体查询" class="router-link-active router-link-exact-active sidebar-item" aria-label="响应式设计和媒体查询"><!--[--><!--]--> 响应式设计和媒体查询 <!--[--><!--]--></a><!----></li><!--]--></ul></li><!--]--></ul></li><li><a href="/preview/dev-edge/frontend/javascript/" class="sidebar-item" aria-label="Javascript"><!--[--><!--]--> Javascript <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><p tabindex="0" class="sidebar-item sidebar-heading collapsible">高级进阶 <span class="right arrow"></span></p><ul style="display:none;" class="sidebar-item-children"><!--[--><li><a href="/preview/dev-edge/frontend/vue/" class="sidebar-item" aria-label="Vue"><!--[--><!--]--> Vue <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><p tabindex="0" class="sidebar-item sidebar-heading collapsible">插件及组件库 <span class="right arrow"></span></p><ul style="display:none;" class="sidebar-item-children"><!--[--><li><a href="/preview/dev-edge/frontend/libs/" class="sidebar-item" aria-label="插件及组件库"><!--[--><!--]--> 插件及组件库 <!--[--><!--]--></a><!----></li><li><a href="/preview/dev-edge/frontend/libs/element.html" class="sidebar-item" aria-label="element UI 快捷代码片段记录"><!--[--><!--]--> element UI 快捷代码片段记录 <!--[--><!--]--></a><!----></li><li><a href="/preview/dev-edge/frontend/libs/others.html" class="sidebar-item" aria-label="其他"><!--[--><!--]--> 其他 <!--[--><!--]--></a><!----></li><!--]--></ul></li><li><p tabindex="0" class="sidebar-item sidebar-heading collapsible">综合 <span class="right arrow"></span></p><ul style="display:none;" class="sidebar-item-children"><!--[--><li><a href="/preview/dev-edge/frontend/others/standard.html" class="sidebar-item" aria-label="前端开发规范"><!--[--><!--]--> 前端开发规范 <!--[--><!--]--></a><!----></li><li><a href="/preview/dev-edge/frontend/others/note.html" class="sidebar-item" aria-label="前端知识点"><!--[--><!--]--> 前端知识点 <!--[--><!--]--></a><!----></li><!--]--></ul></li><!--]--></ul><!--[--><!--]--></aside><!--]--><!--[--><main class="page"><!--[--><!--]--><div class="theme-default-content"><!--[--><!--]--><div><h1 id="css知识点" tabindex="-1"><a class="header-anchor" href="#css知识点" aria-hidden="true">#</a> CSS知识点</h1><h2 id="基础知识" tabindex="-1"><a class="header-anchor" href="#基础知识" aria-hidden="true">#</a> 基础知识</h2><h3 id="什么是css" tabindex="-1"><a class="header-anchor" href="#什么是css" aria-hidden="true">#</a> 什么是css？</h3><p>css是一种用于描述网页样式的语言，全称为cascading style sheets（层叠样式表）。 css可以将html文档中的内容与样式分离，从而使得网页的结构和呈现分离，并且能够使得同样的样式应用于多个页面，从而提高了页面的可维护性和可重用性。</p><p>css允许开发者对html元素进行各种视觉方面的样式控制，包括文字和字体属性、颜色和背景、布局和定位等等。 通过定义不同的样式规则和类别，我们可以轻松地改变网站的外观和感觉。 由于css是一种标记语言，因此使用起来十分灵活和易于理解，也是web前端开发的基础技能之一。</p><h3 id="css的历史和版本" tabindex="-1"><a class="header-anchor" href="#css的历史和版本" aria-hidden="true">#</a> css的历史和版本</h3><p>css是一种用于网页设计的样式表语言，它可以为html文档添加样式和布局效果。css有着悠久的历史，下面是css的历史与版本：</p><p>css1 1996年12月，w3c发布了第一个css标准，即css1。这个版本的css定义了基本的样式属性，如颜色、字体、背景、边框等，并且支持样式层叠和继承。</p><p>css2 1998年5月，w3c发布了css2标准。这个版本的css新增了更多的样式属性，如定位、浮动、清除浮动、伪类、伪元素、表格布局等，并且引入了媒体查询、内容生成和盒模型等新特性。</p><p>css2.1 2004年6月，w3c发布了css2.1标准。这个版本的css对css2进行了修订和完善，但没有引入新的特性。</p><p>css3 css3是css的最新版本，它并不是一个单独的规范，而是由一系列模块组成。每个模块都包含了一个或多个新的css特性。css3的一些主要模块包括：</p><p>selectors level 3：新增了一些高级选择器。 box model：新增了弹性盒子模型和网格布局模型。 color：新增了rgba、hsla和透明度等颜色属性。 text effects：新增了文本阴影、渐变和多列布局等效果。 transitions and animations：新增了过渡和动画效果。 media queries：进一步完善了媒体查询，可以根据设备和屏幕尺寸来设置样式。 css3模块的开发和发布是分散的，并且每个模块都有自己的版本号。因此，css3没有一个明确的版本号，而是根据使用的模块不同而有所不同。</p><h3 id="css语法的结构" tabindex="-1"><a class="header-anchor" href="#css语法的结构" aria-hidden="true">#</a> css语法的结构</h3><p>CSS语法的基本结构如下：</p><p>选择器 { 属性1: 值1; 属性2: 值2; ... }</p><p>其中，选择器表示要应用样式的HTML元素，可以是标签名、类名、ID、属性等；花括号{}中的内容表示要设置的样式属性和对应的取值。</p><p>多个样式规则可以连续书写，以分号分隔。具体示例代码如下：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token selector">h1</span> <span class="token punctuation">{</span>
<span class="token property">color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
<span class="token property">font-size</span><span class="token punctuation">:</span> 24px<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token selector">p</span> <span class="token punctuation">{</span>
<span class="token property">color</span><span class="token punctuation">:</span> blue<span class="token punctuation">;</span>
<span class="token property">font-size</span><span class="token punctuation">:</span> 18px<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>在上面的例子中，h1和p是选择器，它们分别匹配HTML中的<code>&lt;h1&gt;</code>和<code>&lt;p&gt;</code>标记， 并且设置了不同的样式属性。</p><blockquote><p>注意，在样式中使用属性时需要遵循”属性：值“的格式规定，属性和取值之间需要用冒号分隔，多个属性之间需要用分号分隔。</p></blockquote><h3 id="css选择器-如何选择元素" tabindex="-1"><a class="header-anchor" href="#css选择器-如何选择元素" aria-hidden="true">#</a> css选择器，如何选择元素</h3><p>CSS 选择器是用于选择单个或一组 HTML 元素，并对其应用样式的模式。 下面是一些常见的 CSS 选择器示例以及如何使用它们来选择元素：</p><ul><li>标签选择器（element selector）： 通过指定 HTML 标签名来选择所有具有该标记的元素。 例如，要选择所有段落元素，可以使用 p 标签选择器。</li></ul><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token selector">p</span> <span class="token punctuation">{</span>
<span class="token comment">/* 样式 */</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>类选择器 (class selector)： 通过使用 .class 来选择拥有相同 class 属性值的元素。 例如，要选择所有具有 title 类的元素，可以使用 .title 类选择器。</li></ul><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token selector">.title</span> <span class="token punctuation">{</span>
<span class="token comment">/* 样式 */</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>ID 选择器 (id selector)： 通过使用 #id 来选择指定 id 属性的元素。请注意，id 在文档中必须是唯一的。 例如，要选择拥有 main-content ID 的元素，可以使用 #main-content ID 选择器。</li></ul><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token selector">#main-content</span> <span class="token punctuation">{</span>
    <span class="token comment">/* 样式 */</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>后代组合选择器 (descendant combinator)： 通过将选择器分隔符（空格）放置在两个选择器之间来选择元素的后代。 例如，在以下 HTML 结构中，要选择外部 div 下的所有 p 标签，可以使用 div p 选择器。</li></ul><div class="language-html line-numbers-mode" data-ext="html"><pre class="language-html"><code>  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>选我<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>不要选我<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code>  <span class="token selector">div p</span> <span class="token punctuation">{</span>
    <span class="token comment">/* 样式 */</span>
  <span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>子代组合选择器 (child combinator)： 通过使用 &gt; 符号来选择元素的直接子节点。 例如，在以下 HTML 结构中，要选择外部 div 下的所有直接的子元素，可以使用 div &gt; * 选择器（* 表示选择所有元素）。</li></ul><div class="language-html line-numbers-mode" data-ext="html"><pre class="language-html"><code>  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>选我<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>不要选我<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code>  <span class="token selector">div &gt; *</span> <span class="token punctuation">{</span>
    <span class="token comment">/* 样式 */</span>
  <span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>相邻兄弟组合选择器 (adjacent sibling combinator)： 通过使用 + 符号来选择某个元素之后的第一个兄弟元素。 例如，在以下 HTML 结构中，要选择 id 为 heading 的 h2 元素之后的第一个兄弟元素（也就是下一个 p 元素），可以使用 h2 + p 选择器。</li></ul><div class="language-html line-numbers-mode" data-ext="html"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>heading<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>标题<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>选我<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>不要选我<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code>  <span class="token selector">h2 + p</span> <span class="token punctuation">{</span>
    <span class="token comment">/* 样式 */</span>
  <span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>这些只是 CSS 选择器的一部分。可以通过结合使用它们来创建更复杂的选择器，以达到您想要选择的元素。</p><h3 id="css属性和值的基础知识" tabindex="-1"><a class="header-anchor" href="#css属性和值的基础知识" aria-hidden="true">#</a> css属性和值的基础知识</h3><h4 id="css属性" tabindex="-1"><a class="header-anchor" href="#css属性" aria-hidden="true">#</a> CSS属性</h4><p>CSS属性是一种用于设置元素样式的标准化名称。以下是几个常用的CSS属性：</p><ul><li>color</li></ul><p>color属性用于设置文本的颜色。它可以使用颜色名称、十六进制RGB值或RGBA值来指定颜色。</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token property">color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span> <span class="token comment">/* 使用颜色名称 */</span>
<span class="token property">color</span><span class="token punctuation">:</span> #FF0000<span class="token punctuation">;</span> <span class="token comment">/* 使用十六进制RGB值 */</span>
<span class="token property">color</span><span class="token punctuation">:</span> <span class="token function">rgba</span><span class="token punctuation">(</span>255<span class="token punctuation">,</span> 0<span class="token punctuation">,</span> 0<span class="token punctuation">,</span> 0.5<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">/* 使用RGBA值 */</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>font-size font-size属性用于设置字体的大小。它可以使用像素、EM、REM、百分比等单位来指定字体大小。</li></ul><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token property">font-size</span><span class="token punctuation">:</span> 16px<span class="token punctuation">;</span> <span class="token comment">/* 使用像素 */</span>
<span class="token property">font-size</span><span class="token punctuation">:</span> 1.2em<span class="token punctuation">;</span> <span class="token comment">/* 使用EM */</span>
<span class="token property">font-size</span><span class="token punctuation">:</span> 120%<span class="token punctuation">;</span> <span class="token comment">/* 使用百分比 */</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>background-color background-color属性用于设置元素的背景颜色。它可以使用颜色名称、十六进制RGB值或RGBA值来指定背景颜色。</li></ul><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token property">background-color</span><span class="token punctuation">:</span> yellow<span class="token punctuation">;</span> <span class="token comment">/* 使用颜色名称 */</span>
<span class="token property">background-color</span><span class="token punctuation">:</span> #FFFF00<span class="token punctuation">;</span> <span class="token comment">/* 使用十六进制RGB值 */</span>
<span class="token property">background-color</span><span class="token punctuation">:</span> <span class="token function">rgba</span><span class="token punctuation">(</span>255<span class="token punctuation">,</span> 255<span class="token punctuation">,</span> 0<span class="token punctuation">,</span> 0.5<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">/* 使用RGBA值 */</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>margin margin属性用于设置元素的外边距。它可以使用像素、EM、REM、百分比等单位来指定外边距的大小。</li></ul><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token property">margin</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span> <span class="token comment">/* 设置所有方向的外边距为10像素 */</span>
<span class="token property">margin-top</span><span class="token punctuation">:</span> 5em<span class="token punctuation">;</span> <span class="token comment">/* 只设置顶部外边距为5EM */</span>
<span class="token property">margin</span><span class="token punctuation">:</span> 10px 20px 30px 40px<span class="token punctuation">;</span> <span class="token comment">/* 分别设置上右下左四个方向的外边距 */</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>padding padding属性用于设置元素的内边距，也就是元素内容和边框之间的空间。它可以使用像素、EM、REM、百分比等单位来指定内边距的大小。</li></ul><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token property">padding</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span> <span class="token comment">/* 设置所有方向的内边距为10像素 */</span>
<span class="token property">padding-top</span><span class="token punctuation">:</span> 5em<span class="token punctuation">;</span> <span class="token comment">/* 只设置顶部内边距为5EM */</span>
<span class="token property">padding</span><span class="token punctuation">:</span> 10px 20px 30px 40px<span class="token punctuation">;</span> <span class="token comment">/* 分别设置上右下左四个方向的内边距 */</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="css值" tabindex="-1"><a class="header-anchor" href="#css值" aria-hidden="true">#</a> CSS值</h4><p>CSS值表示了CSS属性的可选值。以下是一些常用的CSS值：</p><ul><li>长度单位 长度单位用于指定长度或距离。以下是一些常用的长度单位：</li></ul><p>px：像素（Pixel） em：相对于父元素字体大小的单位 rem：相对于根元素字体大小的单位 %：相对于包含块的百分比</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token property">width</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span> <span class="token comment">/* 使用像素 */</span>
<span class="token property">font-size</span><span class="token punctuation">:</span> 1.2em<span class="token punctuation">;</span> <span class="token comment">/* 相对于父元素字体大小增加20% */</span>
<span class="token property">padding</span><span class="token punctuation">:</span> 2rem<span class="token punctuation">;</span> <span class="token comment">/* 相对于根元素字体大小增加两倍 */</span>
<span class="token property">height</span><span class="token punctuation">:</span> 50%<span class="token punctuation">;</span> <span class="token comment">/* 相对于包含块高度的50% */</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>颜色值 颜色值用于设置颜色。以下是一些常用的颜色值：</li></ul><p>颜色名称：例如red、blue等。 十六进制RGB值：例如#FF0000表示红色，#00FF00表示绿色，#0000FF表示蓝色。 RGBA值：RGBA值与RGB值类似，但是在最后添加了一个alpha通道，它用于控制透明度。</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token property">color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span> <span class="token comment">/* 使用颜色名称 */</span>
<span class="token property">background-color</span><span class="token punctuation">:</span> #FFFF00<span class="token punctuation">;</span>  <span class="token comment">/* 十六进制RGB值 */</span>
<span class="token property">background-color</span><span class="token punctuation">:</span> <span class="token function">rgba</span><span class="token punctuation">(</span>0<span class="token punctuation">,</span>0<span class="token punctuation">,</span>0<span class="token punctuation">,</span>1<span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">/* RGBA值 */</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="css-属性值类型" tabindex="-1"><a class="header-anchor" href="#css-属性值类型" aria-hidden="true">#</a> css 属性值类型</h4><p>css 属性值可以分为以下几种类型：</p><ul><li><p>数字类型 数字类型的值可以是整数或小数，并且可以带有单位，例如像素（px）、百分比（%）、em、rem 等。</p></li><li><p>颜色类型 颜色类型的值可以使用预定义的颜色名称或 rgb/rgba 值、hsl/hsla 值等方式来指定。</p></li><li><p>文本类型 文本类型的值包括字符串、url 和图像名称等。</p></li><li><p>函数类型 函数类型的值由函数名和参数组成，例如 linear-gradient()，它可以生成一个渐变背景。</p></li><li><p>枚举类型 枚举类型的值只能从预定义的选项中选择，例如 display 属性的值可以是 block、inline、inline-block、table 等。</p></li><li><p>逻辑类型 逻辑类型的值表示真假值，例如 visibility 属性的值可以是 visible 或 hidden。</p></li></ul><h4 id="css-单位" tabindex="-1"><a class="header-anchor" href="#css-单位" aria-hidden="true">#</a> css 单位</h4><ul><li><p>绝对单位 绝对单位指的是长度单位，其值相对于物理尺寸而言是固定不变的，例如像素（px）、英寸（in）、厘米（cm）等。</p></li><li><p>相对单位 相对单位指的是长度单位，其值相对于某个基准值而言是可变的，例如百分比（%）、em、rem 等。其中，em 是相对于当前元素的字体大小，rem 是相对于根元素的字体大小。</p></li><li><p>其他单位 css 还支持其他类型的单位，例如时间单位（s、ms）、角度单位（deg、rad、grad）等。</p></li></ul><h4 id="css-值的继承性" tabindex="-1"><a class="header-anchor" href="#css-值的继承性" aria-hidden="true">#</a> css 值的继承性</h4><p>有些 css 属性可以被子元素继承，例如 font-family、color、text-align 等。当一个元素没有设置这些属性时，它会从父元素继承这些属性的值。不过，并非所有属性都有继承性，例如 width、height、border 等就不具有继承性。</p><h4 id="css-值的优先级" tabindex="-1"><a class="header-anchor" href="#css-值的优先级" aria-hidden="true">#</a> css 值的优先级</h4><p>当多个 css 规则应用到同一元素时，可能会出现冲突。 此时，浏览器会根据规则的优先级来决定哪个规则应该生效。css 规则的优先级由以下因素确定：</p><ol><li>指定了 !important 的属性具有最高优先级。</li><li>内联样式具有次高优先级。</li><li>id 选择器的优先级高于类选择器和属性选择器。</li><li>类选择器和属性选择器的优先级相同，但如果它们同时作用于一个元素，则后声明的规则具有更高的优先级。</li><li>元素选择器的优先级最低。 以上是css值的基础知识，掌握了这些知识后，就可以更好地理解和使用css。</li></ol><h2 id="排版和布局" tabindex="-1"><a class="header-anchor" href="#排版和布局" aria-hidden="true">#</a> 排版和布局</h2><h3 id="盒子模型的概念" tabindex="-1"><a class="header-anchor" href="#盒子模型的概念" aria-hidden="true">#</a> 盒子模型的概念</h3><p>盒子模型是指计算机渲染的每个元素都被看作是一个盒子。这个“盒子”由四个边框、内部内容和外边距所组成。它是 Web 设计和开发中最基本的概念之一。在 HTML 和 CSS 中，每个元素都可以通过盒子模型来描述其布局。</p><p>盒子模型包括四个部分：</p><p>内容区域（content area）: 指一个元素包含的实际内容，并且被包围在一个框里，它是盒子模型中的核心。</p><p>填充区域（padding area）: 位于内容区域和边框之间，它的大小可以通过 padding 属性控制。填充区域可以用来设置内容与边框之间的距离。</p><p>边框区域（border area）：是围绕内容和填充区域的线条，可以通过 border 属性进行设置，用来定义元素的边界。</p><p>外边距区域（margin area）：位于边框和周围元素之间，可以通过 margin 属性进行控制，用来调整元素与其他元素之间的距离。</p><p>盒子模型的大小可以通过以下公式计算：</p><div class="language-text line-numbers-mode" data-ext="text"><pre class="language-text"><code>总宽度 = 左边距 + 左边框宽度 + 左填充宽度 + 内容宽度 + 右填充宽度 + 右边框宽度 + 右边距

总高度 = 上边距 + 上边框宽度 + 上填充宽度 + 内容高度 + 下填充宽度 + 下边框宽度 + 下边距
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="w3c盒子模型" tabindex="-1"><a class="header-anchor" href="#w3c盒子模型" aria-hidden="true">#</a> W3C盒子模型</h4><p>W3C盒子模型是Web标准盒子模型，它将元素的宽度和高度属性应用于元素的内容框。这意味着元素的实际宽度和高度不包括填充、边框和边距。如果您想要计算元素的总宽度和高度，您需要将元素的内容框、填充、边框和边距相加。</p><p>以下是W3C盒子模型的示例：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token selector">.box</span> <span class="token punctuation">{</span>
    <span class="token property">width</span><span class="token punctuation">:</span> 200px<span class="token punctuation">;</span>
    <span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
    <span class="token property">padding</span><span class="token punctuation">:</span> 20px<span class="token punctuation">;</span>
    <span class="token property">border</span><span class="token punctuation">:</span> 1px solid black<span class="token punctuation">;</span>
    <span class="token property">margin</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
    <span class="token property">box-sizing</span><span class="token punctuation">:</span> content-box<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>在此示例中，我们定义了一个宽度为200像素、高度为100像素、填充为20像素、1像素黑色边框和10像素边距的盒子。我们还将box-sizing属性设置为content-box，这意味着宽度和高度属性仅适用于元素的内容。</p><h4 id="ie盒子模型" tabindex="-1"><a class="header-anchor" href="#ie盒子模型" aria-hidden="true">#</a> IE盒子模型</h4><p>IE盒子模型是Internet Explorer浏览器使用的盒子模型。它将元素的宽度和高度属性应用于元素的内容框、填充和边框。这意味着元素的实际宽度和高度包括填充和边框，但不包括边距。如果您想要计算元素的总宽度和高度，您需要将元素的内容框、填充和边框相加。</p><p>以下是IE盒子模型的示例：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token selector">.box</span> <span class="token punctuation">{</span>
    <span class="token property">width</span><span class="token punctuation">:</span> 200px<span class="token punctuation">;</span>
    <span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
    <span class="token property">padding</span><span class="token punctuation">:</span> 20px<span class="token punctuation">;</span>
    <span class="token property">border</span><span class="token punctuation">:</span> 1px solid black<span class="token punctuation">;</span>
    <span class="token property">margin</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
    <span class="token property">box-sizing</span><span class="token punctuation">:</span> border-box<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>在此示例中，我们定义了一个宽度为200像素、高度为100像素、填充为20像素、1像素黑色边框和10像素边距的盒子。我们还将box-sizing属性设置为border-box，这意味着宽度和高度属性包括元素的填充和边框。</p><p>盒子模型是Web开发中描述元素在网页上布局的基本概念。</p><p>W3C盒子模型和IE盒子模型是两种不同的盒子模型，它们在计算元素的宽度和高度时有所不同。</p><p>通过理解盒子模型及其工作原理，您可以创建更有效和高效的网页。</p><h3 id="块级元素和行内元素的区别" tabindex="-1"><a class="header-anchor" href="#块级元素和行内元素的区别" aria-hidden="true">#</a> 块级元素和行内元素的区别</h3><p>要理解HTML中块级元素和内联元素之间的区别，我们需要首先了解它们是什么。</p><ul><li><strong>块级元素</strong>：是指占用可用的全部宽度并在元素之后创建新行的元素。</li></ul><p>块级元素的示例包括<code>&lt;div&gt;</code>、<code>&lt;p&gt;</code>、<code>&lt;h1&gt;-6&gt;</code>、<code>&lt;ul&gt;</code>、<code>&lt;ol&gt;</code>、<code>&lt;li&gt;</code>、<code>&lt;table&gt;</code>、<code>&lt;form&gt;</code>和<code>&lt;header&gt;</code>。这些元素通常用于创建网页的结构。</p><ul><li><strong>内联元素</strong>：只占用必要的宽度，并且不会在元素之后创建新行。</li></ul><p>内联元素的示例包括<code>&lt;a&gt;</code>、<code>&lt;span&gt;</code>、<code>&lt;img&gt;</code>、<code>&lt;strong&gt;</code>、<code>&lt;em&gt;</code>和<code>&lt;input&gt;</code>。这些元素通常用于设置块级元素内内容的样式或格式。</p><p>总之：</p><ol><li>块级元素在元素之后创建一条新行，并占用其可用的全部宽度。</li><li>内联元素只占用必要的宽度，不会在元素之后新建一条新行。</li></ol><h3 id="浮动和清除浮动" tabindex="-1"><a class="header-anchor" href="#浮动和清除浮动" aria-hidden="true">#</a> 浮动和清除浮动</h3><p>浮动是一种布局技术，可以使元素脱离文档流并向左或向右移动，直到它们遇到另一个元素或容器的边缘。浮动元素通常用于创建多列布局或图像浮动效果。</p><p>要将元素浮动，可以使用CSS属性float。例如，要将一个元素向左浮动，可以使用以下代码：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token selector">.my-element</span> <span class="token punctuation">{</span>
  <span class="token property">float</span><span class="token punctuation">:</span> left<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>但是，浮动元素可能会导致一些问题，例如它们可能会覆盖其他元素或破坏布局。为了解决这些问题，可以使用清除浮动技术。清除浮动是一种CSS技术，可以将浮动元素的影响限制在其容器内部，从而避免布局问题。</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token selector">.clearfix::after</span> <span class="token punctuation">{</span>
  <span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">;</span>
  <span class="token property">display</span><span class="token punctuation">:</span> table<span class="token punctuation">;</span>
  <span class="token property">clear</span><span class="token punctuation">:</span> both<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>要清除浮动，可以使用CSS属性clear。例如，要清除左浮动，可以使用以下代码：</p><p>这将在浮动元素的容器中创建一个伪元素，并将其清除。请注意，这是一种常见的清除浮动技术，称为“clearfix”。</p><p>总之，浮动是一种布局技术，可以使元素脱离文档流并向左或向右移动，而清除浮动是一种CSS技术，可以避免浮动元素导致的布局问题。</p><h3 id="定位-绝对定位和相对定位" tabindex="-1"><a class="header-anchor" href="#定位-绝对定位和相对定位" aria-hidden="true">#</a> 定位，绝对定位和相对定位</h3><p>定位是指通过CSS属性来设定HTML元素在网页中的位置。有三种常用的定位方式：静态定位、相对定位和绝对定位。</p><ul><li><p>静态定位（position: static）：默认定位方式，即按照文档顺序排列元素，默认不受top、bottom、left、right等属性的影响。</p></li><li><p>相对定位（position: relative）：元素通过top、bottom、left、right的属性进行偏移，根据原来的位置进行相对偏移而影响其他元素的布局位置。例如：</p></li></ul><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code>    <span class="token selector">.box</span><span class="token punctuation">{</span>
        <span class="token property">position</span><span class="token punctuation">:</span> relative<span class="token punctuation">;</span>
        <span class="token property">top</span><span class="token punctuation">:</span> 20px<span class="token punctuation">;</span>
        <span class="token property">left</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>绝对定位（position: absolute）：元素不再占用文档流，通过top、bottom、left、right的属性以及其父元素的相对位置进行偏移。例如：</li></ul><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code>    <span class="token selector">.box</span><span class="token punctuation">{</span>
        <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
        <span class="token property">top</span><span class="token punctuation">:</span> 20px<span class="token punctuation">;</span>
        <span class="token property">left</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="弹性盒子模型-flexbox-的概念" tabindex="-1"><a class="header-anchor" href="#弹性盒子模型-flexbox-的概念" aria-hidden="true">#</a> 弹性盒子模型（flexbox）的概念</h3><p>弹性盒子模型（flexbox）是一种CSS布局模式，可以让容器内的元素自动排列。它为内容提供了显式和隐式的灵活性，使得容器和它的子项能够更好地适应各种各样的屏幕大小和设备类型。</p><p>在使用flexbox布局时，需要将容器的display属性设置为flex或inline-flex。然后可以通过以下属性来控制子项的排列：</p><ul><li>flex-direction：设置主轴的方向</li><li>justify-content：控制子项在主轴上的位置分布</li><li>align-items：控制子项在交叉轴上的位置分布</li><li>flex-wrap：是否允许子项换行</li><li>align-content：多行项目时，控制各行在交叉轴上的位置分布</li></ul><p>例如，下面是一些常用的flexbox属性例子：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token selector">.container</span> <span class="token punctuation">{</span>
  <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
  <span class="token property">justify-content</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
  <span class="token property">align-items</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="网格布局-grid-的概念" tabindex="-1"><a class="header-anchor" href="#网格布局-grid-的概念" aria-hidden="true">#</a> 网格布局（grid）的概念</h3><p>网格布局（grid）是一种CSS布局模式，用于创建类似表格的二维网格布局。它允许开发者以行和列的方式创建一个网格，使得元素可以被放置到这个网格中的特定单元格内。</p><p>在使用Grid布局时，需要在父元素上设置display: grid。然后在父元素中可以通过以下属性来定义网格的大小和排列方式：</p><ul><li>grid-template-columns、grid-template-rows：定义网格列数和行数</li><li>grid-template-areas：定义每个区域的名称</li><li>grid-column-start、grid-column-end、grid-row-start、grid-row-end：将元素放置到具体的行和列中，并占用几个单元格</li></ul><p>例如，下面是一个网格布局的例子：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token selector">.container</span> <span class="token punctuation">{</span>
  <span class="token property">display</span><span class="token punctuation">:</span> grid<span class="token punctuation">;</span>
  <span class="token property">grid-template-columns</span><span class="token punctuation">:</span> <span class="token function">repeat</span><span class="token punctuation">(</span>3<span class="token punctuation">,</span> 1fr<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token property">grid-gap</span><span class="token punctuation">:</span> 10px<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token selector">.item</span> <span class="token punctuation">{</span>
  <span class="token property">grid-column-start</span><span class="token punctuation">:</span> 2<span class="token punctuation">;</span>
  <span class="token property">grid-row-start</span><span class="token punctuation">:</span> 1<span class="token punctuation">;</span>
  <span class="token property">grid-row-end</span><span class="token punctuation">:</span> 3<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>总之，在HTML中，定位、弹性盒子和网格布局是CSS中非常重要的布局方式，可以使得页面元素更加灵活地排列和组织。了解这些技术以及它们的使用方法可以为开发者提供更多选项，并增加Web应用程序的各种效果。</p><h2 id="样式化文本" tabindex="-1"><a class="header-anchor" href="#样式化文本" aria-hidden="true">#</a> 样式化文本</h2><h3 id="字体样式和字体大小" tabindex="-1"><a class="header-anchor" href="#字体样式和字体大小" aria-hidden="true">#</a> 字体样式和字体大小</h3><p>在HTML中，可以通过CSS设置文本的字体和大小。例如，以下是一些示例：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token comment">/* 设置字体 */</span>
<span class="token selector">body</span><span class="token punctuation">{</span>
    <span class="token property">font-family</span><span class="token punctuation">:</span> Arial<span class="token punctuation">,</span> sans-serif<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">/* 设置字体大小 */</span>
<span class="token selector">h1</span><span class="token punctuation">{</span>
    <span class="token property">font-size</span><span class="token punctuation">:</span> 36px<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="文本颜色和背景颜色" tabindex="-1"><a class="header-anchor" href="#文本颜色和背景颜色" aria-hidden="true">#</a> 文本颜色和背景颜色</h3><p>可以通过CSS来改变文本的颜色和背景颜色。例如：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token comment">/* 设置文本颜色 */</span>
<span class="token selector">p</span><span class="token punctuation">{</span>
    <span class="token property">color</span><span class="token punctuation">:</span> #333<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">/* 设置背景颜色 */</span>
<span class="token selector">div</span><span class="token punctuation">{</span>
    <span class="token property">background-color</span><span class="token punctuation">:</span> #f5f5f5<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="文本对齐方式和行高" tabindex="-1"><a class="header-anchor" href="#文本对齐方式和行高" aria-hidden="true">#</a> 文本对齐方式和行高</h3><p>还可以控制文本的对齐方式和行高。例如：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token comment">/* 设置文本对齐方式 */</span>
<span class="token selector">h1</span><span class="token punctuation">{</span>
    <span class="token property">text-align</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">/* 设置行高 */</span>
<span class="token selector">p</span><span class="token punctuation">{</span>
    <span class="token property">line-height</span><span class="token punctuation">:</span> 1.5<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="文本装饰-如下划线、删除线和强调" tabindex="-1"><a class="header-anchor" href="#文本装饰-如下划线、删除线和强调" aria-hidden="true">#</a> 文本装饰，如下划线、删除线和强调</h3><p>可以使用CSS来添加文本效果，例如下划线、删除线和强调等。例如：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token comment">/* 添加下划线 */</span>
<span class="token selector">a</span><span class="token punctuation">{</span>
    <span class="token property">text-decoration</span><span class="token punctuation">:</span> underline<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">/* 添加删除线 */</span>
<span class="token selector">del</span><span class="token punctuation">{</span>
    <span class="token property">text-decoration</span><span class="token punctuation">:</span> line-through<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">/* 设置字体加粗 */</span>
<span class="token selector">b</span><span class="token punctuation">{</span>
    <span class="token property">font-weight</span><span class="token punctuation">:</span> bold<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="阴影和轮廓效果" tabindex="-1"><a class="header-anchor" href="#阴影和轮廓效果" aria-hidden="true">#</a> 阴影和轮廓效果</h3><p>可以使用CSS来为文本添加阴影和轮廓效果。例如：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token comment">/* 添加文本阴影 */</span>
<span class="token selector">h1</span><span class="token punctuation">{</span>
    <span class="token property">text-shadow</span><span class="token punctuation">:</span> 2px 2px 4px #888<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">/* 添加文本轮廓 */</span>
<span class="token selector">h2</span><span class="token punctuation">{</span>
    <span class="token property">text-outline</span><span class="token punctuation">:</span> 1px solid #333<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>在使用这些属性时，需要合适地设置其值以达到最佳效果。</p><h2 id="图像和背景" tabindex="-1"><a class="header-anchor" href="#图像和背景" aria-hidden="true">#</a> 图像和背景</h2><h3 id="背景颜色和背景图像" tabindex="-1"><a class="header-anchor" href="#背景颜色和背景图像" aria-hidden="true">#</a> 背景颜色和背景图像</h3><p>在HTML中，可以通过CSS设置元素的背景颜色和背景图像。例如：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token comment">/* 设置背景颜色 */</span>
<span class="token selector">body</span><span class="token punctuation">{</span>
    <span class="token property">background-color</span><span class="token punctuation">:</span> #f5f5f5<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">/* 设置背景图像 */</span>
<span class="token selector">div</span><span class="token punctuation">{</span>
    <span class="token property">background-image</span><span class="token punctuation">:</span> <span class="token url"><span class="token function">url</span><span class="token punctuation">(</span><span class="token string url">&quot;bg.jpg&quot;</span><span class="token punctuation">)</span></span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="背景尺寸和背景重复" tabindex="-1"><a class="header-anchor" href="#背景尺寸和背景重复" aria-hidden="true">#</a> 背景尺寸和背景重复</h3><p>还可以控制背景图像的尺寸和重复方式。例如：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token comment">/* 设置背景图像的尺寸 */</span>
<span class="token selector">div</span><span class="token punctuation">{</span>
    <span class="token property">background-size</span><span class="token punctuation">:</span> cover<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">/* 设置背景图像不重复 */</span>
<span class="token selector">body</span><span class="token punctuation">{</span>
    <span class="token property">background-repeat</span><span class="token punctuation">:</span> no-repeat<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="边框和圆角" tabindex="-1"><a class="header-anchor" href="#边框和圆角" aria-hidden="true">#</a> 边框和圆角</h3><p>在HTML中，可以通过CSS来添加边框和圆角效果。例如：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token comment">/* 添加边框 */</span>
<span class="token selector">div</span><span class="token punctuation">{</span>
    <span class="token property">border</span><span class="token punctuation">:</span> 1px solid #ddd<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">/* 添加圆角 */</span>
<span class="token selector">img</span><span class="token punctuation">{</span>
    <span class="token property">border-radius</span><span class="token punctuation">:</span> 50%<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="图像透明度和过渡效果" tabindex="-1"><a class="header-anchor" href="#图像透明度和过渡效果" aria-hidden="true">#</a> 图像透明度和过渡效果</h3><p>还可以使用CSS来控制图像的透明度和过渡效果。例如：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token comment">/* 设置图像透明度 */</span>
<span class="token selector">img</span><span class="token punctuation">{</span>
    <span class="token property">opacity</span><span class="token punctuation">:</span> 0.8<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">/* 设置过渡效果 */</span>
<span class="token selector">div</span><span class="token punctuation">{</span>
    <span class="token property">transition</span><span class="token punctuation">:</span> width 2s<span class="token punctuation">,</span> height 2s<span class="token punctuation">;</span>
    <span class="token comment">/* 在:hover时改变宽高 */</span>
    <span class="token selector">&amp;:hover</span> <span class="token punctuation">{</span>
        <span class="token property">width</span><span class="token punctuation">:</span> 200px<span class="token punctuation">;</span>
        <span class="token property">height</span><span class="token punctuation">:</span> 200px<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>这些CSS属性可以帮助开发人员为网站添加更多的视觉效果和交互性。要注意的是，在使用这些属性时，需要谨慎选择其值以达到最佳效果，并确保其不会影响网页的性能和可用性。</p><h2 id="动画和交互" tabindex="-1"><a class="header-anchor" href="#动画和交互" aria-hidden="true">#</a> 动画和交互</h2><h3 id="css动画和关键帧" tabindex="-1"><a class="header-anchor" href="#css动画和关键帧" aria-hidden="true">#</a> css动画和关键帧</h3><p>CSS动画和关键帧是使元素动起来的重要方式。使用CSS关键帧（@keyframes）规则定义动画，然后将其应用到特定元素上。</p><p>以下是一个简单的CSS动画示例：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token comment">/* 定义动画 */</span>
<span class="token atrule"><span class="token rule">@keyframes</span> slide</span> <span class="token punctuation">{</span>
    <span class="token selector">0%</span> <span class="token punctuation">{</span>
        <span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">translateX</span><span class="token punctuation">(</span>0<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token selector">100%</span> <span class="token punctuation">{</span>
        <span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">translateX</span><span class="token punctuation">(</span>300px<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">/* 应用到元素上 */</span>
<span class="token selector">div</span> <span class="token punctuation">{</span>
    <span class="token property">animation</span><span class="token punctuation">:</span> slide 2s ease forwards<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>在这个例子中，我们首先定义了一个名为slide的动画，并为其定义了两个关键帧，从0%到100%它将元素从左侧移动到右侧。然后，在元素上应用了slide动画，并设置其时间、缓动以及完成后是否保持最后状态。</p><h3 id="css过渡效果" tabindex="-1"><a class="header-anchor" href="#css过渡效果" aria-hidden="true">#</a> css过渡效果</h3><p>CSS过渡是另一种常见的动画方式，可以平滑地将元素的某些属性值从一个状态转换到另一个状态。例如：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token comment">/* 设置初始状态 */</span>
<span class="token selector">div</span> <span class="token punctuation">{</span>
    <span class="token property">width</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
    <span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
    <span class="token property">background-color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
    <span class="token property">transition</span><span class="token punctuation">:</span> all 0.5s ease<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">/* 设置悬停状态 */</span>
<span class="token selector">div:hover</span> <span class="token punctuation">{</span>
    <span class="token property">width</span><span class="token punctuation">:</span> 200px<span class="token punctuation">;</span>
    <span class="token property">height</span><span class="token punctuation">:</span> 200px<span class="token punctuation">;</span>
    <span class="token property">background-color</span><span class="token punctuation">:</span> green<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>在这个例子中，当用户将鼠标悬停在div元素上时，该元素将从初始状态平滑地过渡到悬停状态。</p><h3 id="悬停效果和活动状态效果" tabindex="-1"><a class="header-anchor" href="#悬停效果和活动状态效果" aria-hidden="true">#</a> 悬停效果和活动状态效果</h3><p>除了使用过渡和动画外，还可以为元素添加其他视觉效果，例如悬停效果和活动状态效果。例如：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token comment">/* 设置悬停效果 */</span>
<span class="token selector">a:hover</span> <span class="token punctuation">{</span>
    <span class="token property">text-decoration</span><span class="token punctuation">:</span> underline<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">/* 设置活动状态效果 */</span>
<span class="token selector">a:active</span> <span class="token punctuation">{</span>
    <span class="token property">background-color</span><span class="token punctuation">:</span> #ddd<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>在这个例子中，当用户将鼠标指针移到链接上时，该链接的下划线将被显示出来；当用户激活（点击）该链接时，一个灰色背景将被应用。</p><h3 id="响应式设计和媒体查询" tabindex="-1"><a class="header-anchor" href="#响应式设计和媒体查询" aria-hidden="true">#</a> 响应式设计和媒体查询</h3><p>响应式设计是一种使网站适应不同设备屏幕尺寸的方法。通过使用CSS媒体查询，可以检测并适应不同的屏幕尺寸。</p><p>以下是一个简单的响应式设计示例：</p><div class="language-css line-numbers-mode" data-ext="css"><pre class="language-css"><code><span class="token comment">/* 当屏幕宽度小于600px时 */</span>
<span class="token atrule"><span class="token rule">@media</span> <span class="token punctuation">(</span><span class="token property">max-width</span><span class="token punctuation">:</span> 600px<span class="token punctuation">)</span></span> <span class="token punctuation">{</span>
    <span class="token selector">body</span> <span class="token punctuation">{</span>
        <span class="token property">font-size</span><span class="token punctuation">:</span> 14px<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">/* 当屏幕宽度大于600px时 */</span>
<span class="token atrule"><span class="token rule">@media</span> <span class="token punctuation">(</span><span class="token property">min-width</span><span class="token punctuation">:</span> 601px<span class="token punctuation">)</span></span> <span class="token punctuation">{</span>
    <span class="token selector">body</span> <span class="token punctuation">{</span>
        <span class="token property">font-size</span><span class="token punctuation">:</span> 16px<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>在这个例子中，我们为body元素设置了两组不同的字体大小，分别对应于屏幕宽度小于600px和大于600px的情况。当屏幕尺寸符合其中之一时，相应的样式将被应用。</p><p>总之，在HTML中，CSS动画和过渡可以帮助开发人员为网站添加视觉效果，并增强交互性；悬停效果和活动状态效果可以改进网页的可用性；响应式设计可以使网页适应不同设备屏幕尺寸。了解这些技术以及如何正确使用它们可以提高Web应用程序的质量和用户体验。</p></div><!--[--><!--]--></div><footer class="page-meta"><!----><!----><!----></footer><nav class="page-nav"><p class="inner"><span class="prev"><a href="/preview/dev-edge/frontend/html/" class="" aria-label="HTML基础知识"><!--[--><!--]--> HTML基础知识 <!--[--><!--]--></a></span><span class="next"><a href="/preview/dev-edge/frontend/javascript/" class="" aria-label="Javascript"><!--[--><!--]--> Javascript <!--[--><!--]--></a></span></p></nav><!--[--><!--]--></main><!--]--></div><!----><!--]--></div>
    <script type="module" src="/preview/dev-edge/assets/app-5517e208.js" defer></script>
  </body>
</html>
